import axios from "axios";

const LC_SERVER_BASE_URL = "/";

export function getPagedMapListByCondition(params, success, fail) {
  axios
    .post(LC_SERVER_BASE_URL + "map/findPagedMapListByCondition", params)
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function addMap(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "map/create", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateMap(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "map/update", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateMapState(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "map/updateState", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function getDistrictListByCondition(params, success, fail) {
  axios
    .post(LC_SERVER_BASE_URL + "district/findDistrictListByCondition", params)
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function getDistrictTreeByCondition(params, success, fail) {
  axios
    .post(LC_SERVER_BASE_URL + "district/findDistrictTreeByCondition", params)
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function getProvinceAndCityTree(params, success, fail) {
  axios
    .post(LC_SERVER_BASE_URL + "district/findProvinceAndCityTree", params)
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function addDistrict(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "district/create", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateDistrict(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "district/update", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function enableDistrict(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "district/enable", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function disableDistrict(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "district/disable", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function deleteDistrict(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "district/delete", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function getOrganizationListByCondition(params, success, fail) {
  axios
    .post(
      LC_SERVER_BASE_URL + "organization/findOrganizationListByCondition",
      params
    )
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function getPagedOrganizationListByCondition(params, success, fail) {
  axios
    .post(
      LC_SERVER_BASE_URL + "organization/findPagedOrganizationListByCondition",
      params
    )
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function addOrganization(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "organization/create", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateOrganization(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "organization/update", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateOrganizationState(params, success, fail) {
  axios
    .post(LC_SERVER_BASE_URL + "organization/updateState", params)
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function getPagedParameterListByCondition(params, success, fail) {
  axios
    .post(
      LC_SERVER_BASE_URL + "parameter/findPagedParameterListByCondition",
      params
    )
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function addParameter(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "parameter/create", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateParameter(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "parameter/update", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateParameterState(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "parameter/updateState", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function getPagedDeviceListByCondition(params, success, fail) {
  axios
    .post(LC_SERVER_BASE_URL + "device/findPagedDeviceListByCondition", params)
    .then(res => {
      if (res.data.success) {
        success(res.data.data);
      } else {
        if (typeof fail === "function") {
          fail(res.data);
        }
      }
    });
}

export function addDevice(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "device/create", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateDevice(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "device/update", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}

export function updateDeviceState(params, success, fail) {
  axios.post(LC_SERVER_BASE_URL + "device/updateState", params).then(res => {
    if (res.data.success) {
      success(res.data.data);
    } else {
      if (typeof fail === "function") {
        fail(res.data);
      }
    }
  });
}
